<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateGoodsEvaluateAPIRequest;
use App\Http\Requests\API\UpdateGoodsEvaluateAPIRequest;
use App\Models\GoodsEvaluate;
use App\Repositories\GoodsEvaluateRepository;
use App\ZL\Controllers\ApiBaseController;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class GoodsEvaluateController
 * @package App\Http\Controllers\API
 */

class GoodsEvaluateAPIController extends ApiBaseController
{
    /** @var  GoodsEvaluateRepository */
    private $goodsEvaluateRepository;
    protected $model_name = 'App\Models\GoodsEvaluate';
    protected $model_load_array = [
//        'categories','attributes','contents','slideshow'
    ];

    protected $search_field_array = [
        'goods_id'
    ];

    public function __construct(GoodsEvaluateRepository $goodsEvaluateRepo)
    {
        $this->goodsEvaluateRepository = $goodsEvaluateRepo;
    }

    public function _after_get($data)
    {
        $data->load('order');
        $data->load('goods');
        $data->load('attribute');
        $data->load('user');
        $data = $data->toArray();
        foreach ($data as &$item) {
            $pics = json_decode($item['pictures'],true);
            $item['pictures'] = $pics?$pics:[];
        }
        return $data;
    }

    public function _after_find(&$data)
    {
        $data->order;
        $data->goods;
        $data->attribute;
        $data->user;
        $data_arr = $data->toArray();
        $pics = json_decode($data_arr['pictures'],true);
        $data_arr['pictures'] = $pics?$pics:[];
        return $data_arr;
    }

}
